package com.qingfeng.core.config.mongo;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.io.Serializable;

/**
 * @description:
 * @author:LWY
 * @date: 2017/11/24 17:04
 * @modified:
 */
public class MonogoPageable implements Serializable, Pageable {
    private int pageNumber = 1;
    private int pageSize = 20;
    private Sort sort;

    @Override
    public int getPageNumber() {
        return pageNumber;
    }

    @Override
    public int getPageSize() {
        return pageSize;
    }

    @Override
    public int getOffset() {
        return (pageNumber - 1) * pageSize;
    }

    @Override
    public Sort getSort() {
        return sort;
    }

    @Override
    public Pageable next() {
        pageNumber++;
        return this;
    }

    @Override
    public Pageable previousOrFirst() {
        pageNumber--;
        return this;
    }

    @Override
    public Pageable first() {
        pageNumber = 1;
        return this;
    }

    @Override
    public boolean hasPrevious() {
        return pageNumber == 1 ? false : true;
    }


    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setSort(Sort sort) {
        this.sort = sort;
    }

    public MonogoPageable(int pageNumber, int pageSize) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
    }

    public MonogoPageable(int pageNumber, int pageSize, Sort sort) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.sort = sort;
    }

    public MonogoPageable() {
    }
}
